package cn.miao.middle.cloud.log.service.impl;

import java.util.Date;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.miao.middle.cloud.core.model.SysLog;
import cn.miao.middle.cloud.core.util.Validator;
import cn.miao.middle.cloud.datasource.annotation.DataSource;
import cn.miao.middle.cloud.log.mapper.LogMapper;
import cn.miao.middle.cloud.log.service.LogService;

/**
 * 切换数据源，存储log-center
 * 
 * @author kongyufei
 *
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, SysLog> implements LogService {

	@Async
	@Override
	@DataSource(name = "log")
	public void saveLogs(SysLog log) {
		if(Validator.isNullOrEmpty(log.getCreateTime())) {
			log.setCreateTime(new Date());
		}
		if(Validator.isNullOrEmpty(log.getFlag())) {
			log.setFlag(Boolean.TRUE);
		}
		this.baseMapper.insert(log);
	}

}
